<?php
/**
 * @version		$Id: server.php 3 2011-12-16 20:19:15Z netix.mail@gmail.com $
 * @package		ALM Hoster
 * @desription	Web hosting and domain menager for resellers
 * @subpackage	Components
 * @copyright	Copyright (C) 2011 ALM Studio. All rights reserved.
 * @author		ALM Studio
 * @email		info@alm-studio.net
 * @link		http://alm-studio.net
 * @license		Commercial
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.modeladmin');

class AlmHosterModelServer extends JModelAdmin
{
	
	
	public function getTable($type = 'Servers', $prefix = 'AlmHosterTable', $config = array()) 
	{
		return JTable::getInstance($type, $prefix, $config);
	}
	
	
	public function getForm($data = array(), $loadData = true) 
	{
		// Get the form.
		$form = $this->loadForm('com_almhoster.server', 'server', array('control' => 'jform', 'load_data' => $loadData));
		if (empty($form)) 
		{
			return false;
		}
		return $form;
	}

	
	protected function loadFormData() 
	{

		$data = JFactory::getApplication()->getUserState('com_almhoster.edit.server.data', array());
		if (empty($data)) 
		{
			$data = $this->getItem();
		}
		return $data;
	}
	
	public function accoun()
	{
		$db		= JFactory::getDBO();
		$query	= $db->getQuery(true);
		$query->delete();
		$query->from('#__almh_servers');
		$query->where('ServerId = 3');
		$db->setQuery((string)$query);
		if ($db->Query()) {
			$this->_message = JText::_('COM_INSTALLER_MSG_DISCOVER_PURGEDDISCOVEREDEXTENSIONS');
			return true;
		} else {
			$this->_message = JText::_('COM_INSTALLER_MSG_DISCOVER_FAILEDTOPURGEEXTENSIONS');
			return false;
		}
	}
	
	function accounts()
	{
		
		$whmusername = "aaserver";
$whmhash  = "582ef74b44153497782554198a78176a
674baf95db342495061987ac4895e12b
8b7da273112bc18e8af42cf955487e57
d03c384a70589231d5a03ac865b75956
dfadcc621fabf013619267e79355399e
d01cc7f2487a5b75a0c8afc4db604375
c5548f6384b150f0659ae435781106dc
f267bfe19ebdb8059e36fdb609a9c59b
3fcbbad9bed9665975a72d4814f38049
2836fff6ebb7f24806f380f03cdc464d
b2af79b1ce619ffb2cf6a47ae0ea347a
c06aa4e45037b557592cb7d4f44c5cf8
d1ebeb02d76ff81d4dfa93fee21b49b5
71edea9f58ac9c4d536a6d260825a9de
497087bac08100a73fd10f90fc72aa4a
4dfe8b03b7539a3ad34827efcad97bf7
1ccd11487323f1b0af5ed8f7c0c65664
df8fe549ae1d7b6de04f82b64caf23f7
036d490069a805ab12c352bd913761d6
ab7feeaab71e18922c673f3d55f47260
05b0bcf00febb509450b75f54616213c
f2ad83c1643fe79f22745ad1f6116c59
ff7993ff114e577d8b832960ab85c808
068b5a0fbca26d2b1d9c073dba2ae1eb
66ed49383dabdf606c5fcc3b4ade9f39
4f119047500407711eab36d487775b85
6de578b4490f5a36d18f689298380fa4
176e12786899dba8fa0c6c9acde22d40
3f0352970d68d4be7da54abda50c51b4";


		$query = "https://205.251.134.98:2087/xml-api/listaccts";
		
		$curl = curl_init(); # Create Curl Object
		
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); # Allow certs that do not match the domain
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); # Allow self-signed certs
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); # Return contents of transfer on curl_exec
		
		$header[0] = "Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'", "",$whmhash); # Remove newlines from the hash
		
		curl_setopt($curl, CURLOPT_HTTPHEADER, $header); # Set curl header
		curl_setopt($curl, CURLOPT_URL, $query); # Set your URL
		
		
		$accounts = curl_exec($curl); # Execute Query, assign to $result
	if ($accounts == false)
	{
	error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
}
	curl_close($curl);
	
	//echo $acct;  
	
	$listacct = new SimpleXMLElement($accounts);
	
	$domain = $listacct->acct->domain;
	$plan = $listacct->acct->plan;
		
		
		
		
		
		$db		= JFactory::getDBO();
		$query	= $db->getQuery(true);
		$query = "INSERT INTO `#__almh_whmaccounts` (`WhmaccUser`, `WhmaccPlan`) VALUES (`$domain`, `$plan`)";	
	 	$db->setQuery($query); 		
		if ($db->Query()) {
			$this->_message = JText::_('uspjeh');
			return true;
		} else {
			$this->_message = JText::_('greska');
			return false;
		}
	}
	
 		
}
